package org.hu.controller;

import org.hu.model.Employee;
import org.hu.model.Meeting;
import org.hu.model.MeetingDTO;
import org.hu.service.EmployeeService;
import org.hu.service.MeetingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 *预定会议
 * @author Htrees
 */
@Controller
public class BookingController {
    @Autowired
    MeetingService meetingService;
    @Autowired
    EmployeeService employeeService;

    /**
     * 展示我预定的会议
     * @param model
     * @param session
     * @return mybookings
     */
    @RequestMapping("/mybookings")
    String mybookings(Model model, HttpSession session){
        Employee currentuser = (Employee) session.getAttribute("currentuser");
        List<MeetingDTO> mts = meetingService.getMyBookMt(currentuser.getEmployeeid());
        model.addAttribute("mts",mts);
        return "mybookings";
    }

    /**
     * 展示我预定的会议详情
     * @param meetingid 会议id
     * @param model
     * @return mymeetingdetails
     */
    @RequestMapping("/mymeetingdetails")
    String mymeetingdetails(Integer meetingid,Model model){
        Meeting meeting = meetingService.getMtById(meetingid);
        model.addAttribute("mt",meeting);
        List<Employee> listEmployee = employeeService.getEmpsByid(meetingid);
        model.addAttribute("emps",listEmployee);
        return "mymeetingdetails";
    }

    /**
     * 取消会议页面
     * @param meetingid 会议id
     * @param model
     * @return cancelmeeting
     */
    @RequestMapping("/cancelmeeting")
    String cancelmeeting(Integer meetingid,Model model)
    {
        model.addAttribute("mt",meetingService.getMtById(meetingid));
        return "cancelmeeting";
    }

    /**
     * 执行取消会议
     * @param reason 取消原因
     * @param meetingid 会议id
     * @return mybookings
     */
    @RequestMapping("/doCancel")
    String doCancel(String reason,Integer meetingid){
        meetingService.cancelMeeting(meetingid,reason);
        return "redirect:/mybookings";
    }
}
